package com.meichis.yndms.ui.activity;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.meichis.yndms.R;
import com.meichis.yndms.adapter.ProductArrivalAdapter;
import com.meichis.yndms.databinding.ActivityProductArrivalBinding;
import com.meichis.yndms.ui.common.BaseActivity;
import com.meichis.yndms.vm.ProductArrivalVM;

public class ProductArrivalActivity extends BaseActivity {


    private ActivityProductArrivalBinding binding;
    private ProductArrivalVM vm;
    private ProductArrivalAdapter adapter;

    @Override
    protected void setDataBindingContentView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_product_arrival);
        vm = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ProductArrivalVM.class);
        binding.setLifecycleOwner(this);
    }

    @Override
    protected void init() {
        binding.navigation.txtTitle.setText("本月到货量");
        binding.navigation.navBack.setOnClickListener(v -> onBackPressed());
        adapter = new ProductArrivalAdapter(this, R.layout.item_product_arrival);
        binding.rc.setAdapter(adapter);
        binding.rc.setLayoutManager(new LinearLayoutManager(this));
        vm.getMonthProductArrivalByBrand();

        vm.getShowDialog().observe(this, aBoolean -> showLoading(aBoolean));
        vm.getAllDatas().observe(this, businessBoards -> adapter.setList(businessBoards));
    }
}
